package com.tanhua.dubbo.api.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.User;
import com.tanhua.dubbo.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 服务接口实现类
 */
@Service
public class UserApiImpl implements UserApi{

    @Autowired
    private UserMapper userMapper;

    /**
     *完成用户保存返回用户id
     * @param user
     * @return
     */
    @Override
    public Long saveUser(User user) {
        user.setPassword("123456");
        userMapper.insert(user);
        return user.getId();
    }

    /**
     * 根据手机号码查询用户功能
     * @param mobile
     * @return
     */
    @Override
    public User queryByMobile(String mobile) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile",mobile);
        return userMapper.selectOne(queryWrapper);
    }

    /**
     * 根据用户id查询用户功能(不需要再查询直接从UserHoler.getUser().getMobile())
     */
    @Override
    public User queryByMobile(Long userId) {
        return userMapper.selectById(userId);
    }
}
